package com.ysd.lis.service.bac.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.bac.BacGermMorphologyType;
import com.ysd.lis.mapper.bac.BacGermMorphologyTypeMapper;
import com.ysd.lis.request.bac.MorphologyTypeParam;
import com.ysd.lis.service.bac.BacGermMorphologyTypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菌落形态类 服务实现类
 * </p>
 *
 * @author wanghao
 * @since 2024-04-03
 */
@Service
public class BacGermMorphologyTypeServiceImpl extends ServiceImpl<BacGermMorphologyTypeMapper, BacGermMorphologyType> implements BacGermMorphologyTypeService {

    @Autowired
    BacGermMorphologyTypeMapper morphologyTypeMapper;

    @Override
    public Result findPageList(MorphologyTypeParam morphologyTypeParam) {

        LambdaQueryWrapper<BacGermMorphologyType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //参数
        if (!StringUtils.isEmpty(morphologyTypeParam.getSearchValue())) {
            lambdaQueryWrapper.and(wrapper ->
                    wrapper.like(BacGermMorphologyType::getCode, morphologyTypeParam.getSearchValue())
                            .or().like(BacGermMorphologyType::getName, morphologyTypeParam.getSearchValue()));
        }
        lambdaQueryWrapper.eq(BacGermMorphologyType::getDelFlag, 0);
        lambdaQueryWrapper.orderByAsc(BacGermMorphologyType::getMorphologyType);
        lambdaQueryWrapper.orderByAsc(BacGermMorphologyType::getSeq);
        List<BacGermMorphologyType> bacGermMorphologyTypes = morphologyTypeMapper.selectList(lambdaQueryWrapper);
        return Result.succ(bacGermMorphologyTypes);
    }

    @Override
    public Result findListByType(BacGermMorphologyType bacGermMorphologyType) {
        LambdaQueryWrapper<BacGermMorphologyType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(BacGermMorphologyType::getMorphologyType, bacGermMorphologyType.getMorphologyType());
        lambdaQueryWrapper.eq(BacGermMorphologyType::getDelFlag, 0);
        lambdaQueryWrapper.orderByAsc(BacGermMorphologyType::getSeq);
        List<BacGermMorphologyType> bacGermMorphologyTypes = morphologyTypeMapper.selectList(lambdaQueryWrapper);
        return Result.succ(bacGermMorphologyTypes);
    }
}
